'''
    说明：这个文件主要介绍一些列表的使用
'''

'''
    列表可以包含任意类型

list = ['songhao',3.14,12,None]
print(list)
'''


'''
    根据下标获取列表中的元素

list = ['songhao',3.14,12,None]
print(list[0])
print(list[3])
print(list[-1])
'''


'''
    列表中的切片获取子列表

list = ['songhao',3.14,12,None]
print(list[0:2])
'''


'''
    获取列表的元素个数

list = ['songhao',3.14,12,None]
print(len(list))
'''


'''
    用下表改变列表中的元素的值

list = ['songhao',3.14,12,None]
list[3] = 'end'
print(list)
'''


'''
    列表连接和列表复制

list = [1,2,3] + ['A','B','C']
print(list)

list = ['x','y'] * 3
print(list)
'''


'''
    使用del和remove()删除列表中的值

list = ['songhao',3.14,12,None]
del list[3]
print(list)

list = ['songhao',3.14,12,None]
list.remove('songhao')
print(list)
'''


'''
    列表添加元素

catNames = []
while True:
    print('Enter the name of cat ' + str(len(catNames) + 1))
    name = input()
    if name == '' or name == 'exit':
        break
    catNames = catNames + [name]
print('The cat names are:')
for name in catNames:
    print(' ' + name)
'''


'''
    列表用于循环

for i in [0,1,2,3]:
    print(i)
'''


'''
    列表用于循环，并获取对一个的下标

names = ['songhao','amy','haha']
for i in range(len(names)):
    print('Index ' + str(i) + ' in supplies is:' + names[i])
'''


'''
    in和not in的使用

if 'songhao' in ['songhao','amy','haha']:
    print('列表包含元素')
else:
    print('列表不包含元素')
'''


'''
    赋值技巧

properties = ['songhao',27,'male']
name = properties[0]
age = properties[1]
sex = properties[2]

#或者使用下面的赋值
name,age,sex = properties
'''


'''
    使用index对元素进行查找

words = ['hello','tom','hobby','welcome']
print(words.index('hello'))

下面会报错
words = ['hello','tom','hobby','welcome']
print(words.index('hello2'))
'''

'''
    append()和insert()方法在列表中添加元素

words = ['hello','hobby']
words.append('cat')
print(words)

words = ['hello','hobby']
words.insert(0,'cat')
print(words)
'''


'''
    使用sort()对列表中的元素排序

#升序
numbers = [2,5,3.14,1,-7]
numbers.sort()
print(numbers)

#降序
numbers = [2,5,3.14,1,-7]
numbers.sort(reverse=True)
print(numbers)
'''


'''
    copy模块，不改变原来的列表

import copy
words = ['A','B','C','D']
cheese = copy.copy(words)
cheese[1] = 42
print(cheese)
print(words)
'''





